<?php

namespace app\admin\controller\userwork;

use app\admin\controller\Base;
use think\Db;

/**
 * 用户组管理
 * Class GroupController
 * @package app\admin\controller\auth
 */
class Financial extends Base
{

	public function index()
	{

		return view();
	}

	public function arap()
	{

		return view();
	}

	public function araplists()
	{
		$map = array();
		$data = array();
		$post = $this->request->param();
		$map[] = ['project_financial.financial_type', 'in', '3,4'];
		$map[] = ['project_financial.price', '>', 0];
		$data['count'] = Db::view('project_financial', 'id,project_id,project_financial,info,financial_type,c_time,uid,price,remind_time')
			->view('project', 'title', 'project_financial.project_id=project.id', 'LEFT')
			->where($map)
			->count();
		$data['data'] = Db::view('project_financial', 'id,project_id,project_financial,info,financial_type,c_time,uid,price,remind_time')
			->view('project', 'title,s_time,e_time', 'project_financial.project_id=project.id', 'LEFT')
			->where($map)
			// ->fetchSql(true)
			->order('project_id desc')->page(input("param.page"), input('param.limit'))->select();
		$color = config('param.project_color');
		$project_financial = config('param.project_financial');
		$financial_type = config('param.financial_type');
		foreach ($data['data'] as &$info) {
			$info['price'] = '<div style="color:' . $color[$info['financial_type']] . '">' . $info['price'] . '</div>';
			$info['financial_type_status'] = $info['financial_type'] == 2 ? 2 : 1;
			$info['financial_type'] = $info['financial_type'] == 0 ? '毛利' : $financial_type[$info['financial_type']];
			$info['project_financial'] = $info['project_financial'] == 0 ? '--' : $project_financial[$info['project_financial']];
			$info['c_time'] == 0 ? $info['c_time'] = '--' : $info['c_time'] = date('Y-m-d H:i:s', $info['c_time']);
			$info['info'] = strip_tags($info['info']);
			$info['remind_time'] == 0 ? $info['remind_time'] = '--' : $info['remind_time'] = date('Y-m-d H:i:s', $info['remind_time']);
		}

		if ($data['count'] > 0 && $data['data']) {
			$data['msg'] = '获取成功';
		} else {
			$data['msg'] = '获取数据为空';
		}
		$data['code'] = 0;
		return json($data);
	}

	public function lists()
	{
		$map = array();
		$data = array();
		$post = $this->request->param();
		$map[] = ['project_financial.project_financial', '=', 8];
		$data['count'] = Db::view('project_financial', 'id,project_id,project_financial,price')
			->view('project', 'title', 'project_financial.project_id=project.id', 'LEFT')
			->where($map)
			->count();
		$data['data'] = Db::view('project_financial', 'id,project_id,project_financial,price')
			->view('project', 'title,s_time,e_time', 'project_financial.project_id=project.id', 'LEFT')
			->where($map)
			// ->fetchSql(true)
			->order('project_id desc')->page(input("param.page"), input('param.limit'))->select();
		foreach ($data['data'] as &$info) {
			$info['s_time'] = $info['s_time'] == 0 ? $info['s_time'] = '__________' : $info['s_time'] = date('Y-m-d', $info['s_time']);
			$info['e_time'] = $info['e_time'] == 0 ? $info['e_time'] = '__________' : $info['e_time'] = date('Y-m-d', $info['e_time']);
			$info['s_time'] = $info['s_time'] . ' 至 ' . $info['e_time'];
		}
		if ($data['count'] > 0 && $data['data']) {
			$data['msg'] = '获取成功';
		} else {
			$data['msg'] = '获取数据为空';
		}
		$data['code'] = 0;
		return json($data);
	}

}